<?php


namespace EchoPHP\Foundation\BootStrap;

use EchoPHP\Foundation\Application;

class HandleSession {

    protected $app;

    public function bootstrap(Application $app) {
        $this->app = $app;

        if (!extension_loaded('memcached')) {
            throw new \InvalidArgumentException('请安装memcached扩展');
        }
        $config = config('session');
        if (isset($config['servers'])) {
            $savePath = [];
            foreach ($config['servers'] as $server) {
                $savePath[] = $server['host'] . ':' . $server['port'] . '?weight=' . $server['weight'];
            }
            ini_set("session.save_handler", "memcached");
            ini_set("session.save_path", implode(';', $savePath));
            //设置session存储有效期
            //ini_set("session.gc_maxlifetime", 1440);
        }
        if (isset($config['auto_start']) && $config['auto_start']) {
            ini_set("session.auto_start", "On");
        } else {
            ini_set("session.auto_start", "Off");
        }

    }
}